/**
 * 定义OperationManagerController运维管理模块
 */
(function(window, angular, undefined){
	/**
	* 定义OperationManagerController运维管理模块
	*/
	var OperationConfigController = angular.module('OperationConfigController', ['ui.router','itfreer','waterCommon','OperatorManagerService']);
	/**
	 * 运维设置控制器 
	 */
	OperationConfigController.controller('OperationConfigController',
		function($state,$sce,$scope,$itfreerHttp,$itfreer,$compile,$http,$waterDataCommon,$httpData,$queryObj,$wdp,$rootScope,$viewData){
			$("#operationConfigContextDiv .idTabs a").bind("click",function(){
				$("#operationConfigContextDiv .idTabs a").removeClass("selected");
				$(this).addClass("selected");
			});
		}
	);
	/**
	 * 参数设置控制器
	 */
	OperationConfigController.controller('ParmConfigController',
		function($state,$sce,$scope,$itfreerHttp,$itfreer,$compile,$http,$waterDataCommon,$httpData,$queryObj,$wdp,$rootScope,$viewData,$NavService){
		$NavService.setSelectedTab("operationManager.parmConfig");
		
		$scope.startChecked = true;
		$scope.editRow={};
		$scope.queryList=function(){
			$waterDataCommon.getPageRows("/Operation/getMonitorParam.do","MonitorParamList",{});
		}
		$scope.addNewParam = function() {
			$scope.editRow={"S_DOMAINNAME":"MONITOR_PARAM","S_ISEDIT":"1","S_ISUSER":"1","I_JB":"1","S_ISCHILD":"1"};
			$itfreer.openWindow("monitorParamWindow");
		};
		$scope.editParam = function(row) {
			$scope.editRow=row;
			$itfreer.openWindow("monitorParamWindow");
		};
		
		$scope.deleteParam = function(row) {
			$.messager.confirm("确认","确定要删除这条记录吗？",function(r){
				if(r){
					$itfreerHttp.deleteByKey("DATA_DEFULATDOMAIN", {S_ID:row.S_ID},function(){
						$.messager.alert("提示","删除成功！","info");
						$scope.queryList();
					})
				}
			});
		};
		$scope.saveMonitorParam = function(isValid){
			$scope.startChecked = true;
			if(!isValid) 
			{
				return;
			}
			$itfreerHttp.save('DATA_DEFULATDOMAIN',$scope.editRow,
				function(d){
					$itfreer.closeWindow('monitorParamWindow');
					$.messager.alert("提示","保存成功","info");
					$scope.queryList();
			});
		}
		
		$scope.queryList();
	});
	/**
	 * 耗材管理
	 */
	OperationConfigController.controller('OperationMaterial',function($state,$scope,$http,$waterDataCommon,$httpData,$queryObj,$wdp,$rootScope){
		$scope.queryObject={};
		$scope.$on('dataPramChanged', function(event, data) {
			$scope.wwtpReportParm = data;
			$scope.queryOperationMaterialList();
	    });
		$scope.waterDataCommon=$waterDataCommon;//翻页
		//获取耗材信息
		$scope.OperationMaterialList={}
		$scope.queryOperationMaterialList = function(){
			$scope.getMaterial();
			$scope.getManufacter();
			$scope.getType();
			$scope.getCode();
			$waterDataCommon.getPageRows("/MaterialReplace/queryOperationMaterial.do","OperationMaterialList",$scope.queryObject,10,1);	
		}
		//获取选框耗材名称
		$scope.getMaterial = function(){
			$waterDataCommon.getPageRows("/MaterialReplace/getMaterialName.do","getMaterialList",10,1);	
		}
		//获得编号
		$scope.getCode = function(){
			$scope.queryObjCode={};
			var selValue=document.getElementById("selname").value;
			$scope.queryObjCode.MATERIAL_NAME = selValue;
			$waterDataCommon.getPageRows("/MaterialReplace/getManufacterCode.do","getCodeList",$scope.queryObjCode,10,1);	
		}
		//获取选框品牌名称
		$scope.getManufacter = function(){
			$waterDataCommon.getPageRows("/MaterialReplace/getManufacterName.do","getManufacterList",10,1);	
		}
		//获取选框型号
		$scope.getType = function(){
			$scope.queryObjType={};
			var selectValue=document.getElementById("sel").value;
			$scope.queryObjType.MANUFACTURER = selectValue;
			$waterDataCommon.getPageRows("/MaterialReplace/getManufacterType.do","getTypeList",$scope.queryObjType,10,1);	
		}
		$scope.periodselect=[{"id":"","text":"无"},{"id":"个","text":"个"},
		                     {"id":"瓶","text":"瓶"},
		                     {"id":"盒","text":"盒"},
		                     {"id":"套","text":"套"},
		                     {"id":"块","text":"块"},
		                     {"id":"根","text":"根"},
		                     {"id":"台","text":"台"}, {"id":"张","text":"张"}
		                     ];
		//打开新建耗材页面
		$scope.openOperationMaterialEdit=function(){
			$scope.OperationMaterial={};
			$scope.detail=false;//用于判断执行的操作是编辑还是新增
			$itfreer.openWindow('operationMaterialEdit',{title:"添加耗材信息",width:800,high:540});
		}
		//打开编辑耗材页面
		$scope.openSaveOperationMaterialEdit=function(derailData){
			$scope.OperationMaterial=angular.copy(derailData);
			$scope.detail=true;//用于判断执行的操作是编辑还是新增
			$itfreer.openWindow('operationMaterialEdit',{title:"编辑耗材信息",width:800,high:540});
		}
		//保存耗材信息
		$scope.insertOperationMaterial=function(OperationMaterial,detail){
			$scope.data=OperationMaterial;
			if($scope.data.MATERIAL_NAME==null||$scope.data.MATERIAL_NAME==undefined){
				$.messager.alert("提示","耗材名称不能为空","info");
				return false;
			}
			if($scope.data.MATERIAL_CODE==null||$scope.data.MATERIAL_CODE==undefined){
				$.messager.alert("提示","耗材编号不能为空","info");
				return false;
			}
			if(detail==true){
				$waterDataCommon.post("/MaterialReplace/updateOperationMaterial.do",$scope.data,function(d){
					$itfreer.closeWindow('operationMaterialEdit');
					$.messager.alert("提示","编辑成功");
					$scope.queryOperationMaterialList();
				});	
			}else{
				$waterDataCommon.post("/MaterialReplace/insertOperationMaterial.do",$scope.data,function(d){
					$itfreer.closeWindow('operationMaterialEdit');
					$.messager.alert("提示","保存成功");
					$scope.queryOperationMaterialList();
				});	
			}
						
		};		
		$scope.queryOperationMaterialList();
		});
	/**
	 * 运维任务管理
	 */
	OperationConfigController.controller('operationTask',function($state,$itfreerHttp,$compile,$scope,$http,$waterDataCommon,$httpData,$queryObj,$wdp,$rootScope,OperationStationJobService){
		$scope.queryObject={};	
		$scope.taskStatus="all";
		$scope.operatetype="";
		$scope.$on('dataPramChanged', function(event, data) {
			$scope.wwtpReportParm = data;
			$scope.operationTaskList();
	    });
		$scope.operationTaskList = function(){
			$scope.queryObject.taskStatus=$scope.taskStatus;
			if($scope.taskStatus=="all"){
				delete $scope.queryObject.taskStatus;
			}
			$waterDataCommon.getPageRows("/TaskQuery/getOperationTaskList.do","TaskList",$scope.queryObject,10,1);	
		};
		
		//获取运维任务项
		$scope.operationJobs=[];
		OperationStationJobService.postQuery("/TaskQuery/getJobList.do",{job_type:"3"},100,1).then(function(data){
			if(data.data){
				var obj=data.data;
				for(var i=0;i<obj.length;i++){
				 var o={};
				 o.id=obj[i].GUID;
				 o.text=obj[i].JOB_NAME;
				 $scope.operationJobs.push(o);
				}
				$('#operationJobs').combobox({ 
					data: $scope.operationJobs, 
					valueField:'id', 
					textField:'text' 
				 });
			}
		});
		//获取站点
		$scope.stationDrop=[];
		$queryObj.QueryStationObj={};
		$queryObj.QueryStationObj.waterType=getWaterType();
		$queryObj.QueryStationObj.BUILD_STATUS='0';
		OperationStationJobService.postQuery("/OperationGroup/getStationList.do",$queryObj.QueryStationObj,100,1).then(function(data){
			if(data.data){
				var obj=data.data;
				for(var i=0;i<obj.length;i++){
				 var o={};
				 o.id=obj[i].EXP_NO;
				 o.text=obj[i].NAME;
				 $scope.stationDrop.push(o);
				}
				$('#stationDrop').combobox({ 
					data: $scope.stationDrop, 
					valueField:'id', 
					textField:'text' 
				 });
			}
		});
		//添加任务行
		$scope.insertTableRow=function(){
			var obj={STATION_ID:"",JOB_ID:"",START:"",OPERATION_GROUP_ID:"",FINISH_BY:"",userList:"userList"+$scope.taskList.length+""};
			$scope.taskList.push(obj);
		}
		//删除任务
		$scope.deleteTableRow=function(index){
			if($scope.taskList.length==1)
			{
				$.messager.alert("提示","必须要有一个任务添加行","info");
				return;
			}
			$scope.taskList.splice(index, 1);
		}
		//打开新建运维任务页面
		$scope.openOperationTaskAdd=function(){
			$scope.taskList=[];
			$scope.taskList=[{STATION_ID:"",JOB_ID:"",START:"",OPERATION_GROUP_ID:"",FINISH_BY:"",userList:"userList0"}];
			$itfreer.openWindow("operationTaskEdit");				
		}
		
		//关闭新建运维任务页面
		$scope.closeOperationTaskEdit=function(){
			$scope.queryObject={};
			$scope.taskList=[];
			$itfreer.closeWindow("operationTaskEdit");				
		}
		//关闭新建运维任务页面
		$scope.closeOperationTaskEdit=function(){
			$scope.queryObject={};
			$scope.taskList=[];
			$itfreer.closeWindow("operationTaskEdit");				
		}
		
		//打开运维任务导出页面
		$scope.openInputExcel=function(){
			$itfreer.openWindow("inputExcel");				
		}
		//运维任务导入
		$scope.InputExcel=function(){
			$scope.queryObject.TEMPPATH=getHostBase()+$scope.TEMPPATH.substring(0,$scope.TEMPPATH.lastIndexOf(':'));
			 $waterDataCommon.post("/TaskQuery/importExcel.do",$scope.queryObject,function(d){
					$.messager.alert("提示","导入成功！");
					$itfreer.closeWindow("inputExcel");
					$scope.TEMPPATH={};
					$scope.operationTaskList();
			});
		}
		//打开编辑运维任务页面
		$scope.openOperationTaskEdit=function(data){
			$scope.queryObject={}
			$scope.queryObject = angular.copy(data)	
			$scope.queryObject.START=$scope.queryObject.START_TIME
			$itfreer.openWindow("operationTaskUpdate");				
		}
		//关闭编辑运维任务页面
		$scope.closeOperationTaskUpdate=function(){
			$scope.queryObject={};
			$itfreer.closeWindow("operationTaskUpdate");				
		}
		/**
		 * 运维任务新增保存
		 */
		$scope.onSaveTask=function(){	
			for(var i=0;i<$scope.taskList.length;i++){
				$scope.queryObject=$scope.taskList[i];
				$scope.queryObject.START_TIME=$scope.queryObject.START+" 00:00:00"
				$scope.queryObject.END_TIME=$scope.queryObject.START+" 23:59:59"
				$scope.queryObject.TASK_STATUS="0";
				$scope.queryObject.TASK_CODE=$scope.queryObject.START_TIME+$scope.queryObject.STATION_ID;
				 $itfreerHttp.save('OP_TASK',$scope.queryObject,function(){    		
				})
			}
			 $.messager.alert('系统提示',"保存成功");	    		 	
				$itfreer.closeWindow('operationTaskEdit');
				$scope.taskList=[];
				$scope.operationTaskList();
			
		}
		/**
		 * 运维任务编辑保存
		 */
		$scope.onUpdateTask=function(task){	
				$scope.queryObject=task;
				$scope.queryObject.START_TIME=task.START+" 00:00:00"
				$scope.queryObject.END_TIME=task.START+" 23:59:59"
				$scope.queryObject.TASK_STATUS="0";
				$scope.queryObject.TASK_CODE=$scope.queryObject.START+$scope.queryObject.STATION_ID;
				 $itfreerHttp.save('OP_TASK',$scope.queryObject,function(){
		    		 $.messager.alert('系统提示',"保存成功");	    		 	
						$itfreer.closeWindow('operationTaskUpdate');
						$scope.taskList=[];
						$scope.operationTaskList();
				})
		}
		
		$scope.operationTaskList();
		$scope.waterDataCommon = $waterDataCommon;
		});
	/**
	 * 运维事件设置控制器
	 */
	OperationConfigController.controller('JobConfigController',
		function($state,$sce,$scope,$itfreerHttp,$itfreer,$compile,$http,$waterDataCommon,$httpData,$queryObj,$wdp,$rootScope,$viewData,$NavService){
		$NavService.setSelectedTab("operationManager.jobConfig");
		
		$scope.JobData={};
		$scope.queryObj={};
		$scope.queryObj.jobQueryObj={};
		$scope.queryObj.paramJobQueryObj={};
		$scope.isAddJob=false;
		$scope.startChecked=false;
		
		//查询运维事件列表
		$scope.queryJobList=function(){
			$waterDataCommon.getPageRows("OPERATION_JOB","operationJobList",$scope.queryObj.jobQueryObj,10,1);
		}
		
		//添加运维事件
		$scope.addJob=function(){
			$scope.isAddJob=true;
			$scope.startChecked=false;
			$scope.JobData={};
			$itfreer.openWindow("add_operation_job");		
		}
		
		//保存运维事件
		$scope.saveJob=function(JobData, valid){
			$scope.startChecked = true;
			if(!valid){
				return;
			}
			
			// 添加运维事件（事件库）
			$itfreerHttp.save('OPERATION_JOB',$scope.JobData,function(){		
				if($scope.isAddJob){
					$waterDataCommon.getPageRows("OPERATION_JOB","operationJobList",$scope.queryObj.jobQueryObj,10,1,function(){
						$waterDataCommon.lastPage($httpData.operationJobList,$scope.queryObj.jobQueryObj);
					});			
				}
				
				$itfreer.closeWindow("add_operation_job");
				$.messager.alert('系统提示',"保存成功");
						
			});
		}
		
		//关闭运维事件
		$scope.closeJob=function(job){
			$itfreer.closeWindow("add_operation_job");
		}
		
		$scope.queryParam=function(job){
			$wdp.viewValue.JOB = job;
			$state.go("operation_param_job");
		}
		
		//编辑运维事件
		$scope.editJob=function(job){
			$scope.isAddJob=false;
			$scope.startChecked=false;
			$scope.JobData = job;
			$itfreer.openWindow("add_operation_job");
		}
		
		//删除运维事件
		$scope.deleteJob=function(job){
			$scope.queryObj.paramJobQueryObj.JOB_ID = job.GUID;
			$waterDataCommon.getPageRows("/Operation/getParamJob.do","operationParamJobList",$scope.queryObj.paramJobQueryObj,10,1,function(data){
	    		 if(data.data.length<1){    			 
	    			 $.messager.confirm("确认","确定要删除这条记录吗？",function(r){
	    					if(r){
	    						$itfreerHttp.deleteByKey("OPERATION_JOB",{GUID:job.GUID},function(){
		    						$.messager.alert('系统提示',"删除成功！");
		    						$waterDataCommon.getPageRows("OPERATION_JOB","operationJobList",$scope.queryObj.jobQueryObj,$httpData.operationJobList.pageSize,$httpData.operationJobList.pageIndex);
		    					})
	    					}
	    				});
	    		 }
	    		 else{
	    			 $.messager.alert('系统提示',"事件关联参数，无法删除！");
	    		 }
			})	
		}
				
		$scope.waterDataCommon = $waterDataCommon;	
	})
	
	
	/**
	 * 运维事件参数设置控制器
	 */
	OperationConfigController.controller('ParamJobConfigController',
		function($state,$sce,$scope,$itfreerHttp,$itfreer,$compile,$http,$waterDataCommon,$httpData,$queryObj,$wdp,$rootScope,$viewData,$NavService){
		$NavService.setSelectedTab("operationManager.paramJobConfig");
		
		$scope.ParamJobData={};
		$scope.queryObj={};
		$scope.queryObj.paramJobQueryObj={};
		$scope.isAddJob=false;
		$scope.startChecked=false;
		
		//查询运维事件参数列表
		$scope.queryParamJobList=function(){
			$scope.queryObj.paramJobQueryObj.JOB_ID = $wdp.viewValue.JOB.GUID;
			$waterDataCommon.getPageRows("/Operation/getParamJob.do","operationParamJobList",$scope.queryObj.paramJobQueryObj,10,1);
		}
		
		//添加运维事件参数
		$scope.addParamJob=function(){
			$scope.isAddJob=true;
			$scope.startChecked=false;
			$scope.ParamJobData={};
			$scope.ParamJobData.NAME = $wdp.viewValue.JOB.JOB_NAME;
			$itfreer.openWindow("add_operation_param_job");		
		}
		
		//保存运维事件参数
		$scope.saveParamJobs=function(ParamJobData,valid){
			$scope.startChecked = true;
			if(!valid){
				return;
			}
			
			$scope.ParamJobData.JOB_ID = $wdp.viewValue.JOB.GUID;
					
			//循环添加运维事件-参数关系
			getOperationJobParms();
			var params = $scope.ParamJobData.JobParamList.split(",");
			if (params.length<=1){
				$.messager.alert('系统提示',"请选择事件参数");
			}
			
			/*
			for (var i=0; i<params.length; i++){
				var strJobParam = params[i];
				if (strJobParam.length < 1)
					continue;
				
				$scope.ParamJobData.PARM_ID = strJobParam;
				
				$itfreerHttp.save('OC_PARM_EVENT',$scope.ParamJobData,function(){
					console.log($scope.ParamJobData.NAME+$scope.ParamJobData.PARAM_ID);
				});
			}
			*/
			
			$.ajax({
				url:getBasePath() + "/Operation/updateParamJob.do?",
				data:$scope.ParamJobData,
				dataType : 'json',
				success:function(d){
					$scope.queryObj.paramJobQueryObj.JOB_ID = $wdp.viewValue.JOB.GUID;
					$waterDataCommon.getPageRows("/Operation/getParamJob.do","operationParamJobList",$scope.queryObj.paramJobQueryObj,10,1);
					
					$itfreer.closeWindow("add_operation_param_job");
					$.messager.alert('系统提示',"保存成功");
				}
			});
				
		}
		
		//关闭运维事件参数
		$scope.closeParamJob=function(job){
			$itfreer.closeWindow("add_operation_param_job");
		}
		
		//编辑运维事件参数
		$scope.editSingleParamJob=function(job){
			$scope.isAddJob=false;
			$scope.startChecked=false;
			$scope.ParamJobData={};
			
			$scope.ParamJobData.NAME=job.NAME;
			$scope.ParamJobData.GUID=job.PARAM_JOB_GUID;
			$scope.ParamJobData.JOB_ID=job.JOB_ID;
			$scope.ParamJobData.PARM_ID=job.PARM_ID;
			$scope.ParamJobData.DEFAULT_CYCLE=job.DEFAULT_CYCLE;
			$scope.ParamJobData.DEFAULT_TOLERANCE=job.DEFAULT_TOLERANCE;
			
			$scope.ParamJobData.$$hashKey=job.$$hashKey;
			$scope.ParamJobData.FIELD_ISNEW=false;
			$itfreer.openWindow("edit_operation_param_job");
		}
		
		//保存运维事件参数
		$scope.saveSingleParamJob=function(ParamJobData,valid){		
			$itfreerHttp.save('OC_PARM_EVENT',$scope.ParamJobData,function(){
				$scope.queryObj.paramJobQueryObj.JOB_ID = $scope.ParamJobData.JOB_ID;
				$waterDataCommon.getPageRows("/Operation/getParamJob.do","operationParamJobList",$scope.queryObj.paramJobQueryObj,10,1);
				
				$itfreer.closeWindow("edit_operation_param_job");
				$.messager.alert('系统提示',"保存成功");
			});
		}
		
		//删除运维事件参数
		$scope.deleteSingleParamJob=function(job){
			$.messager.confirm("确认","确定要删除这条记录吗？",function(r){
				if(r){
					$itfreerHttp.deleteByKey("OC_PARM_EVENT",{GUID:job.PARAM_JOB_GUID},function(){
						$.messager.alert('系统提示',"删除成功！");
						$scope.queryObj.paramJobQueryObj.JOB_ID = job.JOB_ID;
						$waterDataCommon.getPageRows("/Operation/getParamJob.do","operationParamJobList",$scope.queryObj.paramJobQueryObj,10,1);
					})					
				}
			})
		}
		
		//关闭运维事件参数
		$scope.closeSingleParamJob=function(job){
			$itfreer.closeWindow("edit_operation_param_job");
		}
				
		// 获取查询过滤条件选项
		function getOperationJobParms(){
			var strOperationJobParams = "";
			var parmToCheckDom = $("input[name='OPERATION_JOB_PARAM']:checked"); //运维事件参数
			for(var i=0;i<parmToCheckDom.length;i++){
				var parmName = $(parmToCheckDom[i]).val();
				var parmText = $(parmToCheckDom[i]).attr("parmText");
				strOperationJobParams += $(parmToCheckDom[i]).val()+",";
			}
			
			//使用“,”号分隔的字符串事件参数
			$scope.ParamJobData.JobParamList=strOperationJobParams;	
		}
				
		$scope.waterDataCommon = $waterDataCommon;	
	})
	
	/**
	 * 个人设置搜索面板
	 */
	OperationConfigController.controller('OperatorSearchPanelController',
		function($state,$sce,$scope,$itfreerHttp,$itfreer,$compile,$http,$waterDataCommon,$httpData,$queryObj,$wdp,$rootScope,$viewData){
			$scope.Search = function(){
				var name = $("#operatorSearchTable input[name='name']").val();
				var account = $("#operatorSearchTable input[name='account']").val();
				$wdp.viewValue.operationParm = {'name':name,'account':account};
			}
	})
	/**
	 * 人员设置控制器
	 */
	OperationConfigController.controller('OperatorConfigController',
		function($state,$sce,$scope,$itfreerHttp,$itfreer,$compile,$http,$waterDataCommon,$httpData,$queryObj,$wdp,$rootScope,$viewData){
			$NavService.setSelectedTab("operatorConfig");
			
			if($wdp.viewValue.operationParmWatch){
				$wdp.viewValue.operationParmWatch();
			}
			
			$wdp.viewValue.operationParmWatch = $rootScope.$watch(function(){return $wdp.viewValue.operationParm;},function(){
				$queryObj.operationParm = angular.copy($wdp.viewValue.operationParm);
				$waterDataCommon.getPageRows("/OperationOperator/getOperatorList.do","OperatorList",$queryObj.operationParm,10,1);
	        },true);
			
			$scope.addOperator = function(){
				$itfreer.openWindow('add_operator');
			}
			
		}
	)
	/***
	 * 运维组与站点关系控制器
	 */
	OperationConfigController.controller('GroupStationSearController',	function($state,$sce,$scope,$itfreerHttp,$itfreer,$compile,$http,$waterDataCommon,$httpData,$queryObj,$wdp,$rootScope,$viewData){
		$scope.getOperationGroupData=function(){
			$waterDataCommon.getPageRows("/OperationGroup/getOperatorGroupList.do","groupList",{},10,1,function(d){
				
			});
		};
		$scope.getOperationGroupData();
		$scope.queryObject={};
		$wdp.viewValue.searchData={};
		var strid="";
		$scope.getData=function(){
			$scope.queryObject.GUID=strid.replace(/,/,"");
			$wdp.viewValue.searchData.GUID=$scope.queryObject.GUID;
			$wdp.viewValue.searchData.NAME=$scope.queryObject.NAME;
		}; 
		//控制选择运维组
		$scope.getGuid=function(orgid){
			var li = $("li[orgid='"+orgid+"']");
			if(li.hasClass("selected"))
			{
				li.removeClass('selected');
				if(strid.indexOf(orgid) > 0 ){
					strid=strid.replace(","+orgid,"");
				}
			}
			else{
				li.addClass('selected');
				strid= strid+","+orgid;
			}
			
		};
	});
	//站点运维组列表
	OperationConfigController.controller('GroupStationListController',	function($state,$sce,$scope,$itfreerHttp,$itfreer,$compile,$http,$waterDataCommon,$httpData,$queryObj,$wdp,$rootScope,$viewData){
		$queryObj.QueryStationObj={};
		$scope.savaGroupUnionStationData={};
		$queryObj.QueryStationObj.NAME=	$wdp.viewValue.searchData.NAME;//站点名称
		$queryObj.QueryStationObj.GUID=$wdp.viewValue.searchData.GUID;//运维组ID
		if($wdp.viewValue.searchDataWatch){
			$wdp.viewValue.searchDataWatch();
		}
		$wdp.viewValue.searchDataWatch = $rootScope.$watch(function(){return $wdp.viewValue.searchData;},function(){
			if(!$wdp.viewValue.searchData){
				return;
			}
			$queryObj.QueryStationObj.NAME=	$wdp.viewValue.searchData.NAME;
			$queryObj.QueryStationObj.GUID=$wdp.viewValue.searchData.GUID;
			$queryObj.QueryStationObj.WATER_TYPE=getWaterType();
			$queryObj.QueryStationObj.BUILD_STATUS='0';
			
			$scope.getStationList();
        },true);
		$queryObj.QueryStationObj.waterType=getWaterType();
		$scope.getStationList=function(){
			$waterDataCommon.getPageRows("/OperationGroup/getStationList.do","StationList",$queryObj.QueryStationObj,10,1,function(d){
				
			});
		};
		$scope.getOperationGroupData=function(){
			$waterDataCommon.getPageRows("/OperationGroup/getOperatorGroupList.do","groupList",{},10,1,function(d){
			});
		};
		
		//$scope.getStationList();
		$scope.getOperationGroupData();
		$scope.unionGroup = function(data){
			$scope.savaGroupUnionStationData={};
			$scope.savaGroupUnionStationData.STATION_ID=data.EXP_NO;
			if(data.ASSO_GUID){
				$scope.savaGroupUnionStationData.GUID=data.ASSO_GUID;
				$scope.savaGroupUnionStationData.FIELD_ISNEW=false;
			   }
			$itfreer.openWindow('add_operatorgroupstation');
		};
		$scope.savaGroupUnionStation=function(){
			var temp = document.getElementsByName("group");
			  for(var i=0;i<temp.length;i++)
			  {
			     if(temp[i].checked){
			    	 $scope.savaGroupUnionStationData.OPERATION_GROUP_ID= temp[i].value;
			         break;
			   }	
			  }
			 $itfreerHttp.save('OPERATION_GROUP_STATION_ASSO',$scope.savaGroupUnionStationData,function(){
	    		 $.messager.alert('系统提示',"保存成功");
					$itfreer.closeWindow('add_operatorgroupstation');
					$scope.getStationList();
			});
		};
		$scope.changGroup=function(data){
			var temp = document.getElementsByName("group");
			  for(var i=0;i<temp.length;i++)
			  {
			     if(temp[i].checked){
			    	 $scope.savaGroupUnionStationData.OPERATION_GROUP_ID= temp[i].value;
			         break;
			   }	
			  }
		}
		$scope.cancleUnion=function(){
			$itfreer.closeWindow('add_operatorgroupstation');
		};
		$scope.waterDataCommon = $waterDataCommon;
	});
	OperationConfigController.controller('GroupSearchController',function($state,$sce,$scope,$itfreerHttp,$itfreer,$compile,$http,$waterDataCommon,$httpData,$queryObj,$wdp,$rootScope,$viewData){
		$queryObj.GroupObj={};
		$scope.queryList=function(){
			$waterDataCommon.getPageRows("OC_GROUP","GroupList",$queryObj.GroupObj,10,1);
		};
		$scope.queryList();
	});
	OperationConfigController.controller('GroupListController',function($itfreer,$itfreerHttp,$state,$httpData,$scope,$waterDataCommon,$queryObj,$wdp,OperationStationJobService){
		//打开增加运维组窗口
		$scope.addGroup = function(){
			$scope.group = {};
			$itfreer.openWindow('add_operatorgroup');
		}
		//打开编辑运维组窗口
		$scope.editGroup = function(group){
			$scope.group = group;
			$itfreer.openWindow('add_operatorgroup');
		}
		//获取运维组列表
		$scope.queryList=function(){
			$waterDataCommon.getPageRows("OC_GROUP","GroupList",$queryObj.GroupObj,10,$httpData.GroupList.pageInfo.pageIndex);
		};
		//保存运维组信息
		$scope.saveGroup=function(group){
			if(group.GROUP_NAME == ""){
				$.messager.alert("","名称不能为空");
			}
			$itfreerHttp.save('OC_GROUP',group,function(){
				$scope.queryList();
				$itfreer.closeWindow('add_operatorgroup');
				$.messager.alert("","保存成功。");
			});
		}
		
		//根据关键字查询用户列表
		$scope.queryUser=function(){
			var groupid = $wdp.viewValue.groupId;
			$scope.queryUnRelateUserList(groupid);			
		}
		//根据运维组获取用户列表
		$scope.queryUserList=function(groupid){
			$httpData.GroupUserList = null;
			$waterDataCommon.getPageRows("/OperationGroup/getGroupUserList.do","GroupUserList",{groupid:groupid},100,1,function(d){
				$("#choosedUserUl").empty();
				for(var i=0;i<d.data.length;i++){
					var userid = d.data[i].S_USERID;
					var userName = d.data[i].C_USEREALNAME;
					$("#choosedUserUl").append("<li class='selected'><a href='#' userid='"+userid+"'>"+userName+"</a><i><a docindex='0' class='dele' ></a></i></li>");
				}
				$("#choosedUserUl li a.dele").unbind("click").bind("click",function(){
					$(this).parent().parent().remove();
				});
			});
		};
		//获取没有关联过的用户列表
		$scope.queryUnRelateUserList=function(groupid){
			var queryKeyWord = $("#user_query_keyword").val();
			$waterDataCommon.getPageRows("/OperationGroup/getUserList.do","UserList",{groupid:groupid,username:queryKeyWord},10,1);
		};
		//打开运维组用户窗口
		$scope.checkGroupUser = function(group){
			$wdp.viewValue.groupId = group.GUID;
			$scope.getAllUsers();
			$scope.getGroupUsers(group.GUID);
			$itfreer.openWindow('selectUnRelateUser',{title:"选择组员 - "+group.GROUP_NAME,resizable:false});
		}
		//选择用户事件
		$scope.chooseUser = function(user){
			var userId = user.S_USERID;
			var userName = user.C_USEREALNAME;
			if($("#choosedUserUl li a[userid='"+userId+"']").length < 1 ){
				$("#choosedUserUl").append("<li><a href='#' userid='"+userId+"'>"+userName+"</a><i><a docindex='0' class='dele' ></a></i></li>");
			}
			$("#choosedUserUl li a.dele").unbind("click").bind("click",function(){
				$(this).parent().parent().remove();
			});
		}
		
		//保存运维组用户
		$scope.saveUserGroup_old = function(){
			var groupid = $wdp.viewValue.groupId;
			var useridLi = $("#choosedUserUl li a[userid]");
			var userids = "";
			
			for(var i=0;i<useridLi.length;i++){
				var userid = $(useridLi[i]).attr("userid");
				userids += userid+",";
			}
			
			$.ajax({
				url:getBasePath() + "/OperationGroup/updateUserGroupRelate.do?userids="+userids+"&groupid="+groupid,
				dataType : 'json',
				success:function(d){
					$itfreer.closeWindow('selectUnRelateUser');
					$.messager.alert("","保存成功");
				}
			});
		}
		
		//保存运维组用户
		$scope.saveUserGroup = function(){
			var groupid = $wdp.viewValue.groupId;
			var userids = "";
			var hasHead = false;
			for(var i=0;i<$scope.resultUsers.length;i++){
				var head = $scope.resultUsers[i].GROUP_HEAD;
				if(!head){
					head="0";
				}
				if('1'==head){
					hasHead=true;
				}
				var userid = $scope.resultUsers[i].S_USERID+":"+head;
				userids += userid+",";
			}
			if(!hasHead){
				$.messager.alert('提示','请设置一名运维组长！','info');
				return;
			}
			
			$.ajax({
				url:getBasePath() + "/OperationGroup/updateUserGroupRelate.do?userids="+userids+"&groupid="+groupid,
				dataType : 'json',
				success:function(d){
					$itfreer.closeWindow('selectUnRelateUser');
					$.messager.alert('提示','保存成功！','info');
				}
			});
		}
		
		$scope.allUsers = [];
		$scope.getAllUsers = function(){
			OperationStationJobService.postQuery("/OperationGroup/getUserList.do",{},1000,1).then(function(data){
				$scope.allUsers =  data.data;
			});
		}
		$scope.getGroupUsers = function(groupid){
			OperationStationJobService.postQuery("/OperationGroup/getGroupUserList.do",{groupid:groupid},100,1).then(function(data){
				$scope.resultUsers =  data.data;
			});
		}
		$scope.selectedUsers=[];
		$scope.resultUsers=[];//参数事件结果
		$scope.resultSelectedUsers=[];//选中的参数事件
		$scope.addUser = function(){
			if($scope.selectedUsers.length==0){
				$.messager.alert('提示','请选择用户','info');
				return;
			}
			angular.forEach($scope.selectedUsers,function(value,key){
				var flag=true;
				angular.forEach($scope.resultUsers,function(rvalue,rkey){
					if(flag && value.S_USERID==rvalue.S_USERID){
						flag=false;
					}
				});
				if(flag){
					$scope.resultUsers.push(value);
				}
			});
		};
		
		$scope.removeUser = function(){
			if($scope.resultSelectedUsers.length==0){
				$.messager.alert('提示','请选择要移除的用户','info');
				return;
			}
			angular.forEach($scope.resultSelectedUsers,function(rvalue,rkey){
				var flag=true;
				for(var i=0;flag && i<$scope.resultUsers.length;i++){
					if(rvalue.S_USERID==$scope.resultUsers[i].S_USERID){
						flag=false;
						$scope.resultUsers.splice(i,1);
					}
				}
			});
		};
		
		$scope.setUserHead = function(){
			if($scope.resultSelectedUsers.length==0) return;
			var user = $scope.resultSelectedUsers[0];
			if(user.GROUP_HEAD=='1') return;
			
			user.GROUP_HEAD='1';
			for(var i=0;i<$scope.resultUsers.length;i++){
				if(user.S_USERID!=$scope.resultUsers[i].S_USERID){
					if($scope.resultUsers[i].GROUP_HEAD=='1'){
						$scope.resultUsers[i].GROUP_HEAD='0';
					}
				}
			}
		}
		$scope.waterDataCommon=$waterDataCommon;
	});
	
	/**
	 * 站点事件查询
	 */
	OperationConfigController.controller('StationJobSearchController',	function($scope,$waterDataCommon,OperationStationJobService){
		//去掉视频延迟函数
		if($wdp.timeout){
			clearTimeout($wdp.timeout); 
		}
		$scope.station='';
		$scope.allJobSelected = false;
		$scope.allParamSelected = false;
		$scope.allCycleSelected = false;
		$scope.operationJobs = [];
		OperationStationJobService.postQuery("/Operation/getOperationJobs.do",{},100,1).then(function(data){
			angular.forEach(data.data,function(value,key){
				value.selected=false;
			})
			$scope.operationJobs = data.data;
		});
		$scope.operationJobParams = [];
		OperationStationJobService.postQuery("/Operation/getOperationJobParams.do",{},100,1).then(function(data){
			angular.forEach( data.data,function(value,key){
				value.selected=false;
			})
			$scope.operationJobParams =  data.data;
		});
		$scope.operationJobCycles = [];
		OperationStationJobService.postQuery("/Operation/getOperationJobCycles.do",{},100,1).then(function(data){
			angular.forEach( data.data,function(value,key){
				value.selected=false;
			})
			$scope.operationJobCycles =  data.data;
		});
		
		$scope.selectAllJob = function(){
			$scope.allJobSelected = !$scope.allJobSelected;
			angular.forEach($scope.operationJobs,function(value,key){
				value.selected = false;
			});
		}
		$scope.selectAllParam = function(){
			$scope.allParamSelected = !$scope.allParamSelected;
			angular.forEach($scope.operationJobParams,function(value,key){
				value.selected = false;
			});
		}
		$scope.selectAllCycle = function(){
			$scope.allCycleSelected = !$scope.allCycleSelected;
			angular.forEach($scope.operationJobCycles,function(value,key){
				value.selected = false;
			});
		}
		$scope.toggleJob = function(row){
			row.selected = !row.selected;
			$scope.allJobSelected = false;
		}
		$scope.toggleParam = function(row){
			row.selected = !row.selected;
			$scope.allParamSelected = false;
		}
		$scope.toggleCycle = function(row){
			row.selected = !row.selected;
			$scope.allCycleSelected = false;
		}
		
		$scope.jobQueryObj={};
		$scope.getStationJobs = function(){
			OperationStationJobService.stationJobQueryObj={};
			OperationStationJobService.stationJobQueryObj.station=$scope.station;
			if(!$scope.allJobSelected){
				var jobids=[];
				angular.forEach($scope.operationJobs,function(value,key){
					if(value.selected){
						jobids.push(value.GUID);
					}
				});
				if(jobids.length>0){
					OperationStationJobService.stationJobQueryObj.jobs=combineArray(jobids);
				}
			}
			if(!$scope.allParamSelected){
				var parmids=[];
				angular.forEach($scope.operationJobParams,function(value,key){
					if(value.selected){
						parmids.push(value.S_DOMAINCODE);
					}
				});
				if(parmids.length>0){
					OperationStationJobService.stationJobQueryObj.params=combineArray(parmids);
				}
			}
			if(!$scope.allCycleSelected){
				var cycleids=[];
				angular.forEach($scope.operationJobCycles,function(value,key){
					if(value.selected){
						cycleids.push(value.S_DOMAINCODE);
					}
				});
				if(cycleids.length>0){
					OperationStationJobService.stationJobQueryObj.cycles=combineArray(cycleids);
				}
			}
			
			function combineArray(arr){
				var str = arr.join("','");
				str="('"+str+"')";
				return str;
			}
			
			$scope.jobQueryObj = OperationStationJobService.stationJobQueryObj;
			$waterDataCommon.getPageRows("/Operation/getOperationStationJobs.do",
					"stationJobsList",$scope.jobQueryObj,10,1);
			//控制选择运维组
			$scope.getGuid=function(orgid){
				var li = $("li[orgid='"+orgid+"']");
				if(li.hasClass("selected"))
				{
					li.removeClass('selected');
					if(strid.indexOf(orgid) > 0 ){
						strid=strid.replace(","+orgid,"");
					}
				}
				else{
					li.addClass('selected');
					strid= strid+","+orgid;
				}
				
			};
		};
		
		$scope.getStationJobs();
	});
	/**
	 * 站点事件列表
	 */
	OperationConfigController.controller('StationJobListController',function($scope,OperationStationJobService,$itfreerHttp,$waterDataCommon){
		$scope.xzqh = [];
		OperationStationJobService.postQuery("/Operation/getXZQH.do",{},100,1).then(function(data){
			angular.forEach(data.data,function(value,key){
				value.selected=false;
			});
			$scope.xzqh =  data.data;
		});
		$scope.toggleXzqh = function(row){
			if(row.selected) return;
			row.selected=true;
			angular.forEach($scope.xzqh,function(value,key){
				if(value!=row){
					value.selected=false;
				}
			});

			$scope.getStations();
		}
		
		$scope.stationType = [];
		OperationStationJobService.postQuery("/Operation/getStationType.do",{},100,1).then(function(data){
			angular.forEach(data.data,function(value,key){
				value.selected=false;
			});
			$scope.stationType =  data.data;
			$scope.stationType.splice(0,0,{S_DOMAINCODE:'allType',S_DOMAINCAPTION:'全部'})
		});
		$scope.toggleStationType = function(row){
			if(row.selected) return;
			row.selected=true;
			angular.forEach($scope.stationType,function(value,key){
				if(value!=row){
					value.selected=false;
				}
			});
			$scope.getStations();
		}
		
		$scope.allStations = [];
		$scope.getStations = function(){
			var queryObj={};
			var going = true;
			angular.forEach($scope.xzqh,function(value,key){
				if(going && value.selected && value.S_DOMAINCODE!='00'){
					queryObj.STATION_ID_LIKE = value.S_DOMAINCODE;
					going=false;
				}
			});
			going=true;
			angular.forEach($scope.stationType,function(value,key){
				if(going && value.selected && value.S_DOMAINCODE!='allType'){
					queryObj.FLOW_TYPE=value.S_DOMAINCODE;
					going=false;
				}
			});
			
			var waterType = getWaterType();
			queryObj.WATER_TYPE = waterType;
			queryObj.BUILD_STATUS='0';
			
			OperationStationJobService.postQuery("/Operation/getStationList.do",queryObj,300,1).then(function(data){
				$scope.allStations =  data.data;
			});
		};
		
		$scope.selectedStations=[];
		$scope.resultStations=[];//站点结果
		$scope.resultSelectedStations=[];//选中的结果站点
		$scope.addStation = function(){
			if($scope.selectedStations.length==0){
				$.messager.alert('提示','请选择站点','info');
				return;
			}
			angular.forEach($scope.selectedStations,function(value,key){
				var flag=true;
				angular.forEach($scope.resultStations,function(rvalue,rkey){
					if(flag && value.CODE==rvalue.CODE){
						flag=false;
					}
				});
				if(flag){
					$scope.resultStations.push(value);
				}
			});
		};
		$scope.addAllStation = function(){
			if($scope.allStations.length==0){
				$.messager.alert('提示','请选择站点','info');
				return;
			}
			angular.forEach($scope.allStations,function(value,key){
				var flag=true;
				angular.forEach($scope.resultStations,function(rvalue,rkey){
					if(flag && value.CODE==rvalue.CODE){
						flag=false;
					}
				});
				if(flag){
					$scope.resultStations.push(value);
				}
			});
		};
		$scope.removeStation = function(){
			if($scope.resultSelectedStations.length==0){
				$.messager.alert('提示','请选择站点','info');
				return;
			}
			angular.forEach($scope.resultSelectedStations,function(rvalue,rkey){
				var flag=true;
				for(var i=0;flag && i<$scope.resultStations.length;i++){
					if(rvalue.CODE==$scope.resultStations[i].CODE){
						flag=false;
						$scope.resultStations.splice(i,1);
					}
				}
			});
		};
		$scope.removeAllStation = function(){
			if($scope.resultStations.length==0){
				$.messager.alert('提示','请选择站点','info');
				return;
			}
			$scope.resultStations=[];
		};
		
		$scope.params = [];
		OperationStationJobService.postQuery("/Operation/getOperationJobParams.do",{}).then(function(data){
			angular.forEach( data.data,function(value,key){
				value.selected=false;
			})
			$scope.params =  data.data;
			$scope.params.splice(0,0,{S_DOMAINCODE:'allParam',S_DOMAINCAPTION:'全部'})
		});
		$scope.toggleParam = function(row){
			if(row.selected) return;
			row.selected=true;
			angular.forEach($scope.params,function(value,key){
				if(value!=row){
					value.selected=false;
				}
			});
			$scope.getJobs();
		}
		
		$scope.allJobs = [];
		$scope.getJobs = function(){
			var queryObj={};
			var going = true;
			angular.forEach($scope.params,function(value,key){
				if(going && value.selected && value.S_DOMAINCODE!='allParam'){
					queryObj.param=value.S_DOMAINCODE;
					going=false;
				}
			});
			
			OperationStationJobService.postQuery("/Operation/getParamJobsList.do",queryObj,100,1).then(function(data){
				$scope.allJobs =  data.data;
			});
		}
		$scope.selectedJobs=[];
		$scope.resultJobs=[];//参数事件结果
		$scope.resultSelectedJobs=[];//选中的参数事件
		$scope.addJob = function(){
			if($scope.selectedJobs.length==0){
				$.messager.alert('提示','请选择事件','info');
				return;
			}
			angular.forEach($scope.selectedJobs,function(value,key){
				var flag=true;
				angular.forEach($scope.resultJobs,function(rvalue,rkey){
					if(flag && value.GUID==rvalue.GUID){
						flag=false;
					}
				});
				if(flag){
					$scope.resultJobs.push(value);
				}
			});
		};
		$scope.addAllJob = function(){
			if($scope.allJobs.length==0){
				$.messager.alert('提示','请选择事件','info');
				return;
			}
			angular.forEach($scope.allJobs,function(value,key){
				var flag=true;
				angular.forEach($scope.resultJobs,function(rvalue,rkey){
					if(flag && value.GUID==rvalue.GUID){
						flag=false;
					}
				});
				if(flag){
					$scope.resultJobs.push(value);
				}
			});
		};
		$scope.removeJob = function(){
			if($scope.resultSelectedJobs.length==0){
				$.messager.alert('提示','请选择事件','info');
				return;
			}
			angular.forEach($scope.resultSelectedJobs,function(rvalue,rkey){
				var flag=true;
				for(var i=0;flag && i<$scope.resultJobs.length;i++){
					if(rvalue.GUID==$scope.resultJobs[i].GUID){
						flag=false;
						$scope.resultJobs.splice(i,1);
					}
				}
			});
		};
		$scope.removeAllJob = function(){
			if($scope.resultJobs.length==0){
				$.messager.alert('提示','请选择事件','info');
				return;
			}
			$scope.resultJobs=[];
		};
		
		$scope.operationJobs = [];
		OperationStationJobService.postQuery("/Operation/getOperationJobs.do",{},100,1).then(function(data){
			angular.forEach(data.data,function(value,key){
				value.selected=false;
			})
			$scope.operationJobs = data.data;
			$scope.operationJobs.splice(0,0,{GUID:'all',JOB_CODE:'all',JOB_NAME:'全部'})
		});
		$scope.toggleJob=function(row){
			if(row.selected) return;
			row.selected=true;
			angular.forEach($scope.operationJobs,function(value,key){
				if(value!=row){
					value.selected=false;
				}
			});
			$scope.filterJob();
		};
		
		$scope.filteredJobs=$scope.resultJobs;
		$scope.filterJob = function(){
			var going = true;
			angular.forEach($scope.operationJobs,function(value,key){
				if(going && value.selected){
					var guid = value.GUID;
					if(guid=='all'){
						$scope.filteredJobs = $scope.resultJobs;
					}
					else{
						$scope.filteredJobs=[];
						angular.forEach($scope.resultJobs,function(rvalue,rkey){
							if(guid==rvalue.JOB_ID){
								$scope.filteredJobs.push(rvalue);
							}
						});
					}
					going=false;
				}
			});
		}
		
		$scope.operationJobCycles = [];
		OperationStationJobService.postQuery("/Operation/getOperationJobCycles.do",{},100,1).then(function(data){
			$scope.operationJobCycles =  data.data;
		});
		
		$scope.defaultCycle=null;
		$scope.setDefaultCycle = function(){
			if($scope.defaultCycle==null) return;
			angular.forEach($scope.filteredJobs,function(value,key){
				value.DEFAULT_CYCLE=$scope.defaultCycle;
				
			});
		};
		
		$scope.operationJobTolerances = [];
		OperationStationJobService.postQuery("/Operation/getOperationJobTolerances.do",{},100,1).then(function(data){
			$scope.operationJobTolerances =  data.data;
		});
		
		$scope.defaultTolerance=null;
		$scope.setDefaultTolerance = function(){
			if($scope.defaultTolerance==null) return;
			angular.forEach($scope.filteredJobs,function(value,key){
				value.DEFAULT_TOLERANCE=$scope.defaultTolerance;
			});
		};
		
		$scope.curStep = 'main';
		$scope.isShowStep = function(curStep){
			return $scope.curStep == curStep;
		}
		
		$scope.addStationJobConfig = function(){
			$scope.goStep('step1');
		};
		
		$scope.goStep = function(step){
			if(step=='step2'){
				if($scope.resultStations.length==0){
					$.messager.alert('提示','请选择站点','info');
					return;
				}
			}else if(step=='step3'){
				if($scope.resultJobs.length==0){
					$.messager.alert('提示','请选择事件','info');
					return;
				}
			}
			$scope.curStep = step;
		};
		
		$scope.saveConfig = function(){
			var resultStationJobs=[];
			angular.forEach($scope.resultStations,function(svalue,skey){
				angular.forEach($scope.resultJobs,function(jvalue,jkey){
					var stationJob={};
					stationJob.STATION_ID=svalue.CODE;
					stationJob.PARM_ID=jvalue.PARM_ID;
					stationJob.TASK_CYCLE = jvalue.DEFAULT_CYCLE;
					stationJob.TASK_TOLERANCE = jvalue.DEFAULT_TOLERANCE; 
					stationJob.EFFECTIVE_TIME = jvalue.EFFECTIVE_TIME; 
					stationJob.JOB_ID = jvalue.JOB_ID;
					resultStationJobs.push(stationJob);
				});
			});
			
			if(resultStationJobs.length==0){
				$.messager.alert("提示","没有需要保存的数据","info");
				return;
			}
			
			$itfreerHttp.saveList('OC_TASK_CONFIG',resultStationJobs,function(){
						$.messager.alert("提示","保存成功","info");
						refreshStationJob();
						$scope.goStep('main');
					},function(){
						$itfreer.closeWindow("add_station_job");
						$.messager.alert("错误",arguments[0].responseText,"error");
						$scope.goStep("main");
					}
			);
		}
		
		$scope.jobQueryObj ={};
		function refreshStationJob(){
			$scope.jobQueryObj = OperationStationJobService.stationJobQueryObj;
			$scope.jobQueryObj.WATER_TYPE = getWaterType();
			$scope.jobQueryObj.BUILD_STATUS = '0';
			$waterDataCommon.getPageRows("/Operation/getOperationStationJobs.do",
					"stationJobsList",$scope.jobQueryObj,10,1);
		}
		
		$scope.deleteStationJob = function(row){
			$.messager.confirm("确认","确定要删除这条记录吗？",function(r){
				if(r){
					$itfreerHttp.deleteByKey("OC_TASK_CONFIG",{GUID:row.GUID},function(){
						$.messager.alert('系统提示',"删除成功！");
						refreshStationJob();
					})					
				}
			})
		}
		
		$scope.getStations();
		$scope.getJobs();
		$scope.waterDataCommon=$waterDataCommon;
	});
	
	//运营单位
	OperationConfigController.controller('YydwSearchController',function($sce,$scope,$itfreerHttp,$itfreer,$compile,$http,$waterDataCommon,$httpData,$queryObj,$wdp,$rootScope,$state){
		$queryObj.yydwQueryObj={};
		$wdp.viewValue.zxjcYydw={};
		$wdp.viewValue.zxjcYydw.IsDetail=false;
		$scope.waterDataCommon = $waterDataCommon;
		
		//查询运营单位列表
		$scope.queryYydwList=function(pagesize,pageindex){
			$waterDataCommon.getPageRows("OPERATIONS_UNIT","yydwList",$queryObj.yydwQueryObj,10,1);
		};
		
		//添加运营单位
		$scope.openAddYydwWindows=function(){
			$scope.startChecked = false;
			$wdp.viewValue.zxjcYydw={};
			$wdp.viewValue.zxjcYydw.isAdd = true;
			$itfreer.openWindow("addZxjcYydw");
		};
		
		//保存运营单位
		$scope.saveZxjcYydw=function(zxjcYydw,valid){
			$scope.startChecked = true;
			if(!valid){
				return;
			}
			
			$itfreerHttp.save('OPERATIONS_UNIT',zxjcYydw,function(){
				$itfreer.closeWindow("addZxjcYydw");
				$.messager.alert('系统提示',"保存成功");
				if($wdp.viewValue.zxjcYydw.isAdd){
					$waterDataCommon.getPageRows("OPERATIONS_UNIT","yydwList",$queryObj.yydwQueryObj,10,1,function(){
						$waterDataCommon.lastPage($httpData.yydwList,$queryObj.yydwQueryObj);
					});			
				}
			});			
		};	
		
		//编辑运营单位
		$scope.modifyZxjcYydw=function(zxjcYydw){
			$wdp.viewValue.zxjcYydw=zxjcYydw;
			$itfreer.openWindow('addZxjcYydw');	
		};
		
		//删除运营单位   
		$scope.deleteZxjcYydw=function(zxjcYydw){
			$.messager.confirm("确认","确定要删除这条记录吗？",function(r){
				if(r){
					$itfreerHttp.deleteByKey("OPERATIONS_UNIT",{GUID:zxjcYydw.GUID},function(){
						$.messager.alert('系统提示',"删除成功！");
						$waterDataCommon.getPageRows("OPERATIONS_UNIT","yydwList",$queryObj.yydwQueryObj,$httpData.yydwList.pageSize,$httpData.yydwList.pageIndex,function(){
						});
					})
				}
			});
		};
		
	});
	/**
	 * 安卓版本配置控制器
	 * AndroidVersionController
	 */
	OperationConfigController.controller('AndroidVersionController',function($sce,$scope,$itfreerHttp,$itfreer,$compile,$http,$waterDataCommon,$httpData,$queryObj,$wdp,$rootScope,$state){
		$queryObj.queryObj={}; 
		$scope.Data={};
		$scope.getData=function(){
			$waterDataCommon.getPageRows("ANDROID_VERSION_CONFIG","VersionList",$queryObj.queryObj,10,1);
		};
		//新建
		$scope.AddVersion=function(){
			$itfreer.openWindow('addVersion');	
		};
		//保存
		$scope.savaData=function(){
			var myDate = new Date();
			$scope.Data.CT=myDate.toLocaleDateString().replace(new RegExp("/",'gm'),'-');
			$scope.Data.URL=getAndroidVersion()+$scope.Data.VERSION_NO;
			$itfreerHttp.save('ANDROID_VERSION_CONFIG',$scope.Data,function(){
				$itfreer.closeWindow("addVersion");
				$.messager.alert('系统提示',"保存成功");
				$scope.getData();	
			});	
		};
		//取消
		$scope.cancle=function(){
			$itfreer.closeWindow("addVersion");
		};
		$scope.getData();
		$scope.waterDataCommon=$waterDataCommon;
	});		
}(window, angular));